{%- import "apostrophe-schemas:macros.html" as schemas -%}
{%- import "apostrophe-ui:components/buttons.html" as buttons -%}


{% macro attachment(field) %}
  <div class="apos-attachment-existing" style="display:none;" data-existing>
    <div class="apos-attachment-preview"><img data-preview src="" alt=""></div>
    <span class="apos-attachment-name" data-name></span>
    <div class="apos-button-group">
      <a class="apos-button apos-button--action" href="#" data-link target="_blank">{{ __ns('apostrophe', "View file") }}</a>
      {% if field.crop or field.aspectRatio %}
        <a class="apos-button apos-button--action" href="#" data-apos-crop-attachment>{{ __ns('apostrophe', "Crop image") }}</a>
      {% endif %}
      {% if field.focalPoint %}
        <a class="apos-button apos-button--action" href="#" data-apos-focal-point-attachment>{{ __ns('apostrophe', "Focal point") }}</a>
      {% endif %}
      {% if field.trash %}
        {{ buttons.danger('Delete File', { action: 'trash' }) }}
      {% endif %}
    </div>
  </div>
  <input type="file" name="{{ field.name }}" style="display:none;" data-uploader />
  {% if not field.readOnly %}{{ buttons.action('Upload File', { action: 'uploader-target' }) }}{% endif %}
{% endmacro %}

{{ schemas.fieldset(data, attachment) }}
